package com.atwork.wuhua.jpush;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

public class MyJPushManager {

    private static MyJPushManager iWSJPushManager;
    private Context context;

    private MyJPushManager() {
    }

    public static MyJPushManager getInstance() {
        if (iWSJPushManager == null) {
            iWSJPushManager = new MyJPushManager();
        }
        return iWSJPushManager;
    }

    public void initPush(Context context) {
        this.context = context;
    }

    public void setAlias(String str) {
        if (TextUtils.isEmpty(str)) {
            Toast.makeText(context, "alias不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!MyJPushUtil.isValidTagAndAlias(str)) {
            Toast.makeText(context, "格式不对", Toast.LENGTH_SHORT).show();
            return;
        }
        //调用JPush API设置Alias
        TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
        tagAliasBean.action = TagAliasOperatorHelper.ACTION_SET;
        TagAliasOperatorHelper.sequence++;
        tagAliasBean.alias = str;
        tagAliasBean.isAliasAction = true;
        //调用JPush API设置Tag
        TagAliasOperatorHelper.getInstance().handleAction(context, TagAliasOperatorHelper.sequence, tagAliasBean);
    }
}
